package langnstats.project.lib.clustering;

import java.util.HashMap;
import java.util.Map;

import langnstats.project.lib.WordType;

/*
 * Wei's heuristic based clustering, Spring 2008
 */

public class WordTypeClusterer extends AbstractClusterer{
	public static enum Type{
		PART_CLUSTERED, WH_CLUSTERED, NN_CLUSTERED, JJ_CLUSTERED, VB_CLUSTERED, IN_CLUSTERED, MD_CLUSTERED, RB_CLUSTERED, TO_CLUSTERED, POS_CLUSTERED, PRP_CLUSTERED, COLON_PERION_CLUSTERED, PUNC_CLUSTERED;
	}

	
	public WordTypeClusterer(){
		assignMap();
	}
	
	private Map<String,Integer> idMap = new HashMap<String,Integer>();
	
	private void assignMap(){
		idMap.put(WordType.CC.getName(), Type.PART_CLUSTERED.ordinal());
		idMap.put(WordType.RP.getName(), Type.PART_CLUSTERED.ordinal());
		
		idMap.put(WordType.WRB.getName(), Type.WH_CLUSTERED.ordinal());
		idMap.put(WordType.WP.getName(), Type.WH_CLUSTERED.ordinal());
		idMap.put(WordType.WDT.getName(), Type.WH_CLUSTERED.ordinal());
		
		idMap.put(WordType.NN.getName(), Type.NN_CLUSTERED.ordinal());
		idMap.put(WordType.NNP.getName(), Type.NN_CLUSTERED.ordinal());
		idMap.put(WordType.NNPS.getName(), Type.NN_CLUSTERED.ordinal());
		idMap.put(WordType.NNS.getName(), Type.NN_CLUSTERED.ordinal());
		idMap.put(WordType.CD.getName(), Type.NN_CLUSTERED.ordinal());
		idMap.put(WordType.EX.getName(), Type.NN_CLUSTERED.ordinal());
		
		idMap.put(WordType.DT.getName(), Type.JJ_CLUSTERED.ordinal());
		idMap.put(WordType.JJ.getName(), Type.JJ_CLUSTERED.ordinal());
		idMap.put(WordType.JJR.getName(), Type.JJ_CLUSTERED.ordinal());
		idMap.put(WordType.JJS.getName(), Type.JJ_CLUSTERED.ordinal());
		
		idMap.put(WordType.IN.getName(), Type.IN_CLUSTERED.ordinal());
		
		idMap.put(WordType.VB.getName(), Type.VB_CLUSTERED.ordinal());
		idMap.put(WordType.VBD.getName(), Type.VB_CLUSTERED.ordinal());
		idMap.put(WordType.VBG.getName(), Type.VB_CLUSTERED.ordinal());
		idMap.put(WordType.VBN.getName(), Type.VB_CLUSTERED.ordinal());
		idMap.put(WordType.VBP.getName(), Type.VB_CLUSTERED.ordinal());
		idMap.put(WordType.VBZ.getName(), Type.VB_CLUSTERED.ordinal());
		
		idMap.put(WordType.MD.getName(), Type.MD_CLUSTERED.ordinal());
		
		idMap.put(WordType.RB.getName(), Type.RB_CLUSTERED.ordinal());
		idMap.put(WordType.RBR.getName(), Type.RB_CLUSTERED.ordinal());
		
		idMap.put(WordType.POS.getName(), Type.POS_CLUSTERED.ordinal());
		
		idMap.put(WordType.PRP.getName(), Type.PRP_CLUSTERED.ordinal());
		idMap.put(WordType.PRP$.getName(), Type.PRP_CLUSTERED.ordinal());
		
		idMap.put(WordType.TO.getName(), Type.TO_CLUSTERED.ordinal());
		
		idMap.put(WordType.COLON.getName(), Type.COLON_PERION_CLUSTERED.ordinal());
		idMap.put(WordType.COMMA.getName(), Type.COLON_PERION_CLUSTERED.ordinal());
		idMap.put(WordType.PERIOD.getName(), Type.COLON_PERION_CLUSTERED.ordinal());
		
		idMap.put(WordType.LEFTPAR.getName(), Type.PUNC_CLUSTERED.ordinal());
		idMap.put(WordType.RIGHTPAR.getName(), Type.PUNC_CLUSTERED.ordinal());
	}
	
	private int getID(String s){
		Integer id = idMap.get(s);
		return id;		
	}
	
	public int getClusterID(WordType wt) {	
		String wtName = wt.getName();

		return getID(wtName);
	}
	
	public double getProbability(WordType wt, double clusterProbability) {
		return clusterProbability/this.countWordTypeInSameCluster(wt);
	}
	public String getName() {
		return "WordTypeClusterer returns no specific name";
	}

}
